﻿@{
    ViewBag.Title = "作品附件列表";
}
<div class="wrapper animated fadeInRight autoHeight">
    <!-- Panel Other -->
    <div class="row autoHeight" style="background-color: #fff;">
        <div class="col-sm-12 col-sm-leftRight">
            <!-- Example Toolbar -->
            <div class="example">
                @*<div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                    <button id="btnEditFile" type="button" class="btn btn-outline btn-primary">
                        <i class="glyphicon glyphicon-pencil" aria-hidden="true">编辑</i>
                    </button>
                </div>*@
                <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
            </div>
            <!-- End Example Toolbar -->
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<div id="org_form" style="width: 460px;height:100%; overflow: hidden; display: none;">
    <form class="form-horizontal m-t" id="orgFormTable" method="post">
        <div class="form-group">
            <label class="col-sm-3 control-label">运行平台：</label>
            <div class="col-sm-7">
                <select id="option_plat" name="option_plat" title="请选择运行平台" class="form-control input-sm selectpicker" placeholder="请选择运行平台"  required="" aria-required="true"></select>
                <input type="hidden" id="option_id" name="option_id" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">头显设备：</label>
            <div class="col-sm-7">
                <select id="head_facility" name="head_facility" title="请选择头显设备" class="form-control input-sm selectpicker" placeholder="请选择头显设备" required="" aria-required="true"></select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">定价<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-7">
                <input id="file_money" name="file_money" type="text" class="form-control input-sm" placeholder="请输入定价" title="请输入定价" required="" aria-required="true" />
            </div>
        </div>
    </form>
</div>
@section footSection{
    <script>
        var fileId, options, $table;
        var fileListManager = {
            initPage: function () {
                showLoadBoxs();
                if (!fileListManager.initData())
                    return false;
                fileListManager.initSelect();
                fileListManager.initTable();
                fileListManager.initBind();
                delLoadBoxs();
            },
            initData: function () {
                fileId = $.getUrls("file_id");
                if (!fileId) {
                    layer.msg("作品ID异常！");
                    return false;
                }
                return true;
            },
            initSelect: function () {
                $('#option_plat').initSelectpicker("docPlat");
                $('#head_facility').initSelectpicker("docHeadFacility");
                $('.selectpicker').selectpicker({ size: 5 });
            },
            initTable: function () {
                options = {
                    url: ctx + "/SourceManager/GetEntryFileListData",
                    cutHeight: 5,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    //toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        params = {
                            rows: params.limit,
                            //页面大小
                            page: params.offset / params.limit + 1,
                            file_id: fileId //作品ID
                        }
                        return params;
                    },
                    columns: [
                        {
                            radio: true
                        },
                        {
                            field: '',//第一列序号
                            title: '序号',
                            align: 'center',
                            width: 50,
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {
                            field: 'option_name',
                            title: '名称',
                            align: 'left',
                            formatter: function (value, row, index) {
                                if (value && value.toString().length > 10)
                                    back = "<span title='" + value + "'>" + value.toString().substring(0, 10) + "...</span>";
                                else
                                    back = value;
                                //if (row.service_id)
                                //    back = "<a href='" + row.service_id + "'>" + back + "</a>";
                                return back;
                            }
                        }, {
                            field: 'file_money',
                            title: '定价',
                            align: 'center'
                        }, {
                            field: 'head_facility',
                            title: '头显设备',
                            align: 'center'
                        }, {
                            field: 'option_plat',
                            title: '运行平台',
                            align: 'center'
                        }, {
                            field: 'option_size',
                            title: '附件大小',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value) 
                                    return value + "M";
                                return "-";
                            }
                        }, {
                            field: 'service_id',
                            title: '附件地址',
                            align: 'left'
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            initBind: function () {
                //编辑
                $('#btnEditFile').on('click', function () {
                    fileListManager.saveForm();
                });
            },
            saveForm: function () {
                var rows = $table.bootstrapTable('getSelections');
                if (!rows || rows.length === 0) {
                    layer.msg("未选中行~", { icon: 5 });
                    return false;
                }
                var row = rows[0];
                //清空表单
                $('#orgFormTable').resetHideValidForm();
                //打开编辑
                layer.open({
                    title: ['编辑附件', 'font-size:18px;'],
                    type: 1,
                    content: $('#org_form'),
                    scroll: true,//是否显示滚动条、默认不显示
                    btn: ['确定', '取消'],
                    area: ['480px', '400px'],
                    success: function (li, o) {
                        if (row != null) {
                            $('#orgFormTable')[0].reset();//重置表单
                            $('#orgFormTable').LoadForm(row);//表单填充数据
                        }
                    },
                    yes: function (li, o) {
                        if ($('#orgFormTable').valid()) {
                            //验证通过
                            $('#orgFormTable').ajaxSubmit({
                                url: ctx + '/SourceManager/SaveEntryFileData',
                                type: "post",
                                dataType: "json",
                                beforeSubmit: function (arr, $form, options) {
                                    layer.msg("提交数据~", { icon: 1, time: 5000 });
                                },
                                success: function (result, status, xhr, $form) {
                                    if (result.Statu === 0) {
                                        layer.msg("数据更新成功！", { icon: 6 });
                                        $table.bootstrapTable('refresh', options);
                                    }                                                                    
                                    else
                                        layer.alert(result.Msg, { icon: 5 });
                                },
                                error: function (xhr, status, error, $form) {
                                    layer.msg("保存失败~", { icon: 5 });
                                }
                            });
                        }
                    },
                    cancel: function (li, o) {

                    }
                });
            }
        }
        $(function () {
            //初始化页面
            fileListManager.initPage();
        });
    </script>
}
